package com.jinmdz.fmis.api.api.controller;

import com.jinmdz.fmis.api.api.model.coldstorage.ColdStorageAllData;
import com.jinmdz.fmis.api.api.model.coldstorage.ColdStorageAllLoadData;
import com.jinmdz.fmis.api.api.model.coldstorage.ColdStorageData;
import com.jinmdz.fmis.api.api.model.common.DataCodeData;
import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.api.service.ColdStorageService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.model.coldstorage.ColdStorageEquipmentViewItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 冷藏任务信息相关接口
 *
 * @author LiCongLu
 * @date 2020-01-20 13:13
 */
@Api(description = "冷藏任务信息相关接口")
@RestController()
@RequestMapping("/api/cold-storage")
public class ColdStorageController extends BaseController {

    @Resource
    private ColdStorageService coldStorageService;

    /**
     * 根据cold_storage表中id加载冷藏任务信息
     *
     * @param data 冷藏主键
     * @return
     * @author LiCongLu
     * @date 2020-01-20 13:14
     */
    @ApiOperation(value = "根据cold_storage表中id加载冷藏任务信息", notes = "根据ID加载冷藏信息")
    @PostMapping("/load-cold-storage-with-id")
    public BaseResult<ColdStorageData> loadColdStorageWithId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> coldStorageService.loadColdStorageWithId(data));
    }

    /**
     * 保存冷藏信息到cold_storage表中
     *
     * @param data 冷藏请求数据
     * @return
     * @author LiCongLu
     * @date 2020-01-20 13:15
     */
    @ApiOperation(value = "保存冷藏信息到cold_storage表中", notes = "保存冷藏任务信息到cold_storage表中")
    @PostMapping("/save-cold-storage")
    public BaseResult<ColdStorageData> saveColdStorage(@RequestBody ColdStorageData data) {
        return resultHandler(data, userItem -> coldStorageService.saveColdStorage(userItem, data));
    }

    /**
     * 从cold_storage表中删除指定id的冷藏任务信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-01-20 13:17
     */
    @ApiOperation(value = "从cold_storage表中删除指定id的冷藏任务信息记录", notes = "从cold_storage表中删除指定id的冷藏任务信息")
    @PostMapping("/delete-cold-storage-with-id")
    public BaseResult deleteColdStorageWithId(@RequestBody IdVersionData data) {
        return resultHandler(data, userItem -> coldStorageService.deleteColdStorageWithId(userItem, data));
    }

    /**
     * 根据冷藏柜类型加载冷藏格位信息
     *
     * @param data 冷藏设备值
     * @return
     * @author LiCongLu
     * @date 2020-01-20 13:18
     */
    @ApiOperation(value = "根据冷藏柜类型加载冷藏格位信息", notes = "根据冷藏柜类型[冷藏柜类型字典编码：equipment_type]加载相应类型的冷藏格位信息")
    @PostMapping("/load-cold-storage-equipment-with-type")
    public BaseResult<ArrayList<ColdStorageEquipmentViewItem>> loadColdStorageEquipmentWithType(@RequestBody DataCodeData data) {
        return resultHandler(data, userItem -> coldStorageService.loadColdStorageEquipmentWithType(data));
    }

    /**
     * 冷藏服务洽谈，界面权限验证及基础数据加载
     *
     * @param data 加载全部数据
     * @return
     * @author LiCongLu
     * @date 2020-01-20 13:19
     */
    @ApiOperation(value = "冷藏服务洽谈，界面权限验证及基础数据加载", notes = "针对页面定制接口，打开冷藏服务洽谈登记界面时使用本方法一次性加载所有界面初始化需要的数据\n" +
            "coldStorageId:冷藏记录ID\n" +
            "dictTypeCodes：冷藏相关字典信息【参数：equipment_type、refrigerated_state】等\n" +
            "serviceItemTypeCode:加载冷藏用物品服务信息【参数：use_in_cold_storage】")
    @PostMapping("/load-cold-storage-all")
    public BaseResult<ColdStorageAllLoadData> loadColdStorageAll(@RequestBody ColdStorageAllData data) {
        return resultHandler(data, userItem -> coldStorageService.loadColdStorageAll(data));
    }
}
